package com.dulichdanang.location.locationCat;

import java.util.ArrayList;
import java.util.List;

import lib.map.MyMedia;

import com.dulichdanang.HomeActivity;
import com.dulichdanang.R;
import com.dulichdanang.location.locations.LocationsActivity;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

public class LocationCatActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_location_cat);
		//Set data demo
//		Bundle re = this.getIntent().getExtras();
//		int title =	re.getInt("data");
//		this.setTitle(title);
		LocationCat locationCat = new LocationCat();
		final List<LocationCat> items = locationCat.getLocationCat();
//		final List<LocationCat> items = new ArrayList<LocationCat>();
//		items.add(new LocationCat(){{
//			id = 1;
//			name = "haha";
//			subTitle = "This is sub title";
//			image = getResources().getDrawable(R.drawable.search_sm);
//		}});
//		items.add(new LocationCat(){{
//			id = 1;
//			name = "haha";
//			subTitle = "This is sub title";
//			image = getResources().getDrawable(R.drawable.search_sm);
//		}});
//		items.add(new LocationCat(){{
//			id = 1;
//			name = "haha";
//			subTitle = "This is sub title";
//			image = getResources().getDrawable(R.drawable.search_sm);
//		}});
//		items.add(new LocationCat(){{
//			id = 1;
//			name = "haha";
//			subTitle = "This is sub title";
//			image = getResources().getDrawable(R.drawable.search_sm);
//		}});
		
		//show log demo data
//		int i = 0;
//		while(i<items.size()){
//			Log.e("id",items.get(i).id+"");
//			Log.e("name",items.get(i).name);
//			i++;
//		}
		LocationCatAdapter adapter = new LocationCatAdapter(this, items);
		ListView lv = (ListView)findViewById(R.id.lvLocationCat);
		lv.setAdapter(adapter);
		OnItemClickListener itemClick = new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(LocationCatActivity.this,LocationsActivity.class);
				intent.putExtra("data", items.get(arg2).id+"-"+items.get(arg2).name);
				startActivity(intent);
//				Toast toast =Toast.makeText(getApplicationContext(), arg2+"", Toast.LENGTH_LONG);
//				toast.show();
//				Log.w(arg2+"",items.get(arg2).id+"");
			}
		};
		lv.setOnItemClickListener(itemClick);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_location_cat, menu);
		return true;
	}

}
